#include "stdio.h"
#include "stdlib.h"

int main()
{
    printf("请输入动态三角矩阵第一行的个数:");
    int num;
    scanf("%d", &num);

    int **triangleMatrix = (int **) malloc(sizeof(int *) * num);
    for (int i = 0; i < num; i++)
    {
        triangleMatrix[i] = (int *) malloc(sizeof(int) * (num - i));
    }

    printf("请输入第一行%d个数的值，以空格分隔:", num);
    for (int i = 0; i < num; i++)
    {
        scanf("%d", triangleMatrix[0] + i);
    }

    for (int i = 1; i < num; i++)
    {
        for (int j = 0; j < (num - i); j++)
        {
            triangleMatrix[i][j] = triangleMatrix[i - 1][j + 1] - triangleMatrix[i - 1][j];
        }
    }

    for (int i = 0; i < num; i++)
    {
        for (int k = 0; k < i; k++)
        {
            printf(" ");
        }

        for (int j = 0; j < (num - i); j++)
        {
            printf("%d ", triangleMatrix[i][j]);
        }

        printf("\n");
    }

    return 0;
}
